//
//  LBKechengListVC.m
//  V-Learn
//
//  Created by Apple on 2019/2/14.
//  Copyright © 2019 yxk. All rights reserved.
//

#import "LBKechengListVC.h"
#import "LBSaomangCell.h"
#import "LBCoureseDetailVC.h"
#import "LBCoureseListModel.h"
#import "CourseDetailsViewController.h"
@interface LBKechengListVC ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *coureseLists;
@property (nonatomic, strong) NSMutableArray *dataArray;

@end

@implementation LBKechengListVC
- (NSMutableArray *)dataArray{
    if (!_dataArray) {
        _dataArray = [NSMutableArray array];
    }
    return _dataArray;
}
- (NSMutableArray *)coureseLists{
    if (!_coureseLists) {
        _coureseLists = [NSMutableArray array];
    }
    return _coureseLists;
}
- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, LBNAVBAR_HEIGHT, ScreenW, ScreenH-LBNAVBAR_HEIGHT) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
    }
    return _tableView;
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = self.titleString;//@"课程";
    [self.view addSubview:self.tableView];
    self.tableView.tableFooterView = [UIView new];
    // tableView 偏移20/64适配
    if (@available(iOS 11.0, *)) {
            self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;//UIScrollView也适用
    }else {
            self.automaticallyAdjustsScrollViewInsets = NO;
    }
        [self requestData];
    
}


- (void)requestData{
    
    NSMutableDictionary *data = [NSMutableDictionary dictionary];
    [data setObject:self.cateId forKey:@"cateId"];
    
    [WYHXNetWorkManager get:WKHomemoreCourse_WKURL params:(NSDictionary *)data completionHandler:^(id responseObj, NSError *error) {
        NSString *code = responseObj[@"code"];
        if (code.integerValue==200) {
//            NSLog(@"%@",responseObj);
            NSArray *arr = [LBSaomiaoAreaModel mj_objectArrayWithKeyValuesArray:responseObj[@"data"]];
            [self.dataArray addObjectsFromArray:arr];
            [self.tableView reloadData];
        }
    }];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;

}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.dataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    LBSaomangCell *cell = [LBSaomangCell cellWithTableView:tableView];
    LBSaomiaoAreaModel *model = self.dataArray[indexPath.section];
    cell.saomangModel = model;
//    if ([[UserModel getUserModel].userId isEqualToString:@"38"]) {
//        cell.priceLab.hidden = YES;
//    }else{
//        cell.priceLab.hidden = NO;
//    }
    cell.freeIcon.hidden = YES;
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 130;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//    LBCoureseListModel *model = self.coureseLists[indexPath.section];
//    CourseDetailsViewController *coureseVC = [CourseDetailsViewController new];
//    coureseVC.packId = model.packId;
//    coureseVC.collectType = @"2";
//    [self.navigationController pushViewController:coureseVC animated:YES];
    LBSaomiaoAreaModel *model = self.dataArray[indexPath.section];
    LBCoureseDetailVC *courseDetailVC = [[LBCoureseDetailVC alloc] init];
    courseDetailVC.courseId = model.courseId;
    courseDetailVC.type = @"1";//model.courseType;
//    courseDetailVC.courseInfo = model.courseInfo;//去掉这个字段在详情页获取
//    NSLog(@"%@%@",model.courseId,model.courseType);
    [self.navigationController pushViewController:courseDetailVC animated:YES];
}

@end
